package com.gz.purchase.library.pojo;

import net.tsz.afinal.annotation.sqlite.OneToMany;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

/**
 * 库存查看界面 商品实体类
 * author wanner1991
 */
public class StorageCheckProductInfo {
    private boolean isSelected ; // 用户是否选中
    private int product_id ;//商品id
    private String product_name;//商品名称
    private String product_unit; //商品单位
    private int product_num; //商品剩余量
    private int shop_id; //供应商id
    private String shop_name;//供应商名称
    private Double product_price;//商品单价
    private int live_num ;// 剩余商品份数 (这个字段，只在入库历史查询 界面使用)

    private int selectNum ;//在出库车出库界面，该字段用来存放代购员填入的数字

    public int getLive_num() {
        return live_num;
    }

    public void setLive_num(int live_num) {
        this.live_num = live_num;
    }

    public int getSelectNum() {
        return selectNum;
    }

    public void setSelectNum(int selectNum) {
        this.selectNum = selectNum;
    }

    public boolean isSelected() {
        return isSelected;
    }

    public void setIsSelected(boolean isSelected) {
        this.isSelected = isSelected;
    }

    public String getProduct_unit() {
        return product_unit;
    }

    public void setProduct_unit(String product_unit) {
        this.product_unit = product_unit;
    }

    public int getProduct_id() {
        return product_id;
    }

    public void setProduct_id(int product_id) {
        this.product_id = product_id;
    }

    public String getProduct_name() {
        return product_name;
    }

    public void setProduct_name(String product_name) {
        this.product_name = product_name;
    }


    public int getProduct_num() {
        return product_num;
    }

    public void setProduct_num(int product_num) {
        this.product_num = product_num;
    }

    public int getShop_id() {
        return shop_id;
    }

    public void setShop_id(int shop_id) {
        this.shop_id = shop_id;
    }

    public String getShop_name() {
        return shop_name;
    }

    public void setShop_name(String shop_name) {
        this.shop_name = shop_name;
    }

    public Double getProduct_price() {
        return product_price;
    }

    public void setProduct_price(Double product_price) {
        this.product_price = product_price;
    }

    public static List<StorageCheckProductInfo> parse(JSONArray array) throws JSONException {
        if (array.length() <= 0 || array == null){
            return null;
        }
        ArrayList<StorageCheckProductInfo> list = new ArrayList<StorageCheckProductInfo>();
        StorageCheckProductInfo info ;
        for (int i = 0 ; i < array.length() ; i++){
            info = new StorageCheckProductInfo();
            JSONObject object = array.getJSONObject(i);
            info.product_id = object.getInt("product_id");
            info.product_name = object.getString("product_name");
            info.product_unit = object.getString("product_unit");
            info.product_num = object.getInt("product_num");
            info.shop_id = object.getInt("shop_id");
            info.shop_name = object.getString("shop_name");
            list.add(info);
        }
        return list;
    }

    /**
     * 出库车出库调用下面这个方法解析
     * @param array
     * @return
     * @throws JSONException
     */
    public static List<StorageCheckProductInfo> parse2(JSONArray array) throws JSONException {
        if (array.length() <= 0 || array == null){
            return null;
        }
        ArrayList<StorageCheckProductInfo> list = new ArrayList<StorageCheckProductInfo>();
        StorageCheckProductInfo info ;
        for (int i = 0 ; i < array.length() ; i++){
            info = new StorageCheckProductInfo();
            JSONObject object = array.getJSONObject(i).getJSONArray("products").getJSONObject(0);
            info.product_id = object.getInt("product_id");
            info.product_name = object.getString("product_name");
            info.product_unit = object.getString("product_unit");
            info.product_num = object.getInt("product_num");
            info.shop_id = object.getInt("shop_id");
            info.shop_name = object.getString("shop_name");
            info.selectNum = info.product_num;
            list.add(info);
        }
        return list;
    }

    /**
     *  入库界面 解析查询到的数据用该方法
     * @param array
     * @return
     * @throws JSONException
     */
    public static List<StorageCheckProductInfo> parse3(JSONArray array) throws JSONException {
        if (array.length() <= 0 || array == null){
            return null;
        }
        ArrayList<StorageCheckProductInfo> list = new ArrayList<StorageCheckProductInfo>();
        StorageCheckProductInfo info ;
        for (int i = 0 ; i < array.length() ; i++){
            info = new StorageCheckProductInfo();
            JSONObject object = array.getJSONObject(i);
            info.product_id = object.getInt("product_id");
            info.product_name = object.getString("product_name");
            info.product_unit = object.getString("product_unit");
            info.shop_id = object.getInt("shop_id");
            info.shop_name = object.getString("shop_name");
            info.selectNum = 1;
            list.add(info);
        }
        return list;
    }

    /**
     * 入库历史查询界面 商品实体的json 解析方法，多了一个 product_price字段
     * @param array
     * @return
     */
    public static List<StorageCheckProductInfo> parse4(JSONArray array) throws JSONException {
        if (array == null || array.length() <= 0){
            return null;
        }

        List<StorageCheckProductInfo> list = new ArrayList<StorageCheckProductInfo>();
        JSONObject object;
        StorageCheckProductInfo info ;

        for (int i = 0 ; i < array.length() ; i ++){

            object = array.getJSONObject(i);
            info = new StorageCheckProductInfo();
            info.product_id = object.getInt("product_id");
            info.product_name = object.getString("product_name");
            info.product_unit = object.getString("product_unit");
            info.product_num = object.getInt("product_num");
            info.live_num = object.getInt("live_num");
            info.shop_id = object.getInt("shop_id");
            info.shop_name = object.getString("shop_name");

            list.add(info);
        }

        return list;
    }


}
